package main

type ListNode struct {
	Val  int
	Next *ListNode
}

/*
 * 1 2 3 4
 * p n
*/
func reverseList(head *ListNode) *ListNode {
	var prev *ListNode
	n := head
	for n != nil {
		next := n.Next
		n.Next = prev
		prev = n
		n = next
	}
	return prev
}

func main() {
	n0 := &ListNode{Val: 1}
	n1 := &ListNode{Val: 2}
	n2 := &ListNode{Val: 3}
	n3 := &ListNode{Val: 4}
	n0.Next = n1
	n1.Next = n2
	n2.Next = n3
	reverseList(n0)
}
